import React, { Component } from 'react';
import { Button } from 'element-react';
export default class StateScreen extends Component {
  state = {
    num : 0
  };
  componentDidMount() {
    // this.setState({
    //   num : this.state.num++
    // });
    // setTimeout(() => {
    //   this.setState({
    //     num : this.state.num++
    //   });
    //   console.log('1000毫秒后', this.state.num); //2
    // }, 1000);
    // this.setState({
    //   num : this.state.num++
    // });
    // setTimeout(() => {
    //   this.setState({
    //     num : this.state.num++
    //   });
    // });
    // this.setState({
    //   num : this.state.num++
    // });

    this.setState((prevState, props) => {
      console.log(prevState.num + 1);
      return prevState.num + 1;
    });

    console.log('num', this.state.num); //3
  }

  /**
   * 点击事件
   * @param event
   */
  clickHandle = (event) => {
    console.log('event', event);
    console.log('event', event.target);
    console.log('event', event.nativeEvent);
  };

  render() {
    console.log('render', this.state.num); //1
    return (
      <div>
        <h2>state</h2>
        <Button onClick={this.clickHandle}>Event</Button>
      </div>
    );
  }
}
